#include<string>
#include<Windows.h>
using std::string;
namespace xmlFunctions{
	bool isSpace(char ch)
	{
		return (ch==' '||ch=='\n');
	}
	string getname(string val,int size)
	{
		string name="";
		bool intag=false;
		for(int i=0;i<size;i++)
		{
			if(val[i]=='<') intag=true;
			else if(val[i]=='>') return name;
			else if(intag) name+=val[i];
		} 
		return name;
	}
	string getval(string val,int size)
	{
		string returnval="";
		bool intagbef=false,outtag=true;
		for(int i=0;i<size;i++)
		{
			if(val[i]=='<'&&!intagbef)
			{
				outtag=false;
				
			}else if(val[i]=='>'&&!intagbef) outtag=true,intagbef=true;
			else if(outtag&&intagbef) returnval+=val[i];
		}
		returnval=returnval.substr(0,returnval.find_last_of('<'));
		return returnval;
	} 
	string UTF8ToGB(const char* str)
	{
	    string result;
	    WCHAR *strSrc;
	    LPSTR szRes;
	    int i = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
	    strSrc = new WCHAR[i+1];
	    MultiByteToWideChar(CP_UTF8, 0, str, -1, strSrc, i);
	    i = WideCharToMultiByte(CP_ACP, 0, strSrc, -1, NULL, 0, NULL, NULL);
	    szRes = new CHAR[i+1];
	    WideCharToMultiByte(CP_ACP, 0, strSrc, -1, szRes, i, NULL, NULL);
	
	    result = szRes;
	    delete []strSrc;
	    delete []szRes;
	    return result;
	}
}
